#encoding=utf8
'''
Created on 2012-10-17

@author: Administrator
'''
from Processor import Processor;
from pub import Func, UserDict, RoomDict;
from pub.Config import Config;

class RICClass(Processor):
    '''
    指令：RIC(room idiom comment)
    备注：用户道具
    格式：c-s:cmd #cmdID#roomID#userID#userIDTo #commetStyle
     s-c:cmd #cmdID#roomID#userID#userIDTo #commetStyle
    '''
    def __init__(self,):
        Processor.__init__(self);
        self.__roomId = 0;
        self.__userIdFrom = 0;
        self.__userIdTo = 0;
        self.__commentType = Config.COMMENT_STYLE_UP;        
        
    def dataValidtor(self, cmdContent):
        if not cmdContent:
            return False;
        paraLen = len(cmdContent);
        if paraLen == 4:
            self.__roomId = Func.strToInt(cmdContent[0], Config.I_SYS_ZERO);
            self.__userIdFrom = Func.strToInt(cmdContent[1], Config.I_SYS_ZERO);
            self.__userIdTo = Func.strToInt(cmdContent[2], Config.I_SYS_ZERO);
            self.__commentType = Func.strToInt(cmdContent[3], Config.COMMENT_STYLE_UP);      
            return True;        
        return False;
    def outData(self,):
        room = RoomDict.getRoomFromDictById(self.__roomId);
        if not room:
            Func.sendError(self._sockObj, self._cmdId, Config.ERROR_MESSAGE_ROOM_DETAIL_NULL + ",roomId:" + Func.toStr(self.__roomId, 0));
            return False;
        userFromNickName="";
        userToNickName="";
        user = RoomDict.findUserInRoom(self.__userIdFrom)[1];
        if not user:
            Func.sendError(self._sockObj, self._cmdId, Config.ERROR_MESSAGE_ROOM_USER_NO + ",userId:" + Func.toStr(self.__userIdFrom, 0));
            return False;
        userFromNickName=user.get_user_nick_name();
        user = RoomDict.findUserInRoom(self.__userIdTo)[1];
        if not user:
            Func.sendError(self._sockObj, self._cmdId, Config.ERROR_MESSAGE_ROOM_USER_NO + ",userId:" + Func.toStr(self.__userIdTo, 0));
            return False;
        userToNickName=user.get_user_nick_name();
        sendStr = self.setPackage([self.__roomId, self.__userIdFrom, userFromNickName,self.__userIdTo, userToNickName,self.__commentType]);
        RoomDict.sendInfoToRoomAllUser(roomObj=room, cmd="", msg=sendStr, isPackage=False);
        
        
        
